//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.yys.excel.yysexcel.utils;

import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.SecureRandom;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;

public class RandomStrg {
    private Integer length = new Integer(8);
    private String randomstr;
    private boolean allchars = false;
    private HashMap hmap;
    private ArrayList lower = null;
    private ArrayList upper = null;
    private char[] single = null;
    private int singlecount = 0;
    private boolean singles = false;
    private String algorithm = null;
    private String provider = null;
    private boolean secure = false;
    private Random random = null;
    private SecureRandom secrandom = null;
    private static long id = 1L;

    public RandomStrg() {
    }

    public void setLength(int count) {
        this.length = new Integer(count);
    }

    private final float getFloat() {
        return this.random == null ? this.secrandom.nextFloat() : this.random.nextFloat();
    }

    public final void generateRandomObject() throws Exception {
        if (this.secure) {
            try {
                if (this.provider != null) {
                    this.random = SecureRandom.getInstance(this.algorithm, this.provider);
                } else {
                    this.random = SecureRandom.getInstance(this.algorithm);
                }
            } catch (NoSuchAlgorithmException var2) {
                throw new Exception(var2.getMessage());
            } catch (NoSuchProviderException var3) {
                throw new Exception(var3.getMessage());
            }
        } else {
            this.random = new Random();
        }

    }

    private final void generaterandom() {
        int i;
        if (this.allchars) {
            for(i = 0; i < this.length; ++i) {
                this.randomstr = this.randomstr + (new Character((char)(34 + (int)(this.getFloat() * 93.0F)))).toString();
            }
        } else if (this.singles) {
            if (this.upper.size() == 3) {
                for(i = 0; i < this.length; ++i) {
                    if ((int)(this.getFloat() * 100.0F) % 2 == 0) {
                        if ((int)(this.getFloat() * 100.0F) % 2 == 0) {
                            this.randomstr = this.randomstr + this.randomSingle().toString();
                        } else {
                            this.randomstr = this.randomstr + this.randomChar((Character)this.lower.get(2), (Character)this.upper.get(2)).toString();
                        }
                    } else if ((int)(this.getFloat() * 100.0F) % 2 == 0) {
                        this.randomstr = this.randomstr + this.randomChar((Character)this.lower.get(1), (Character)this.upper.get(1)).toString();
                    } else {
                        this.randomstr = this.randomstr + this.randomChar((Character)this.lower.get(0), (Character)this.upper.get(0)).toString();
                    }
                }
            } else if (this.upper.size() == 2) {
                for(i = 0; i < this.length; ++i) {
                    if ((int)(this.getFloat() * 100.0F) % 2 == 0) {
                        this.randomstr = this.randomstr + this.randomSingle().toString();
                    } else if ((int)(this.getFloat() * 100.0F) % 2 == 0) {
                        this.randomstr = this.randomstr + this.randomChar((Character)this.lower.get(1), (Character)this.upper.get(1)).toString();
                    } else {
                        this.randomstr = this.randomstr + this.randomChar((Character)this.lower.get(0), (Character)this.upper.get(0)).toString();
                    }
                }
            } else if (this.upper.size() == 1) {
                for(i = 0; i < this.length; ++i) {
                    if ((int)this.getFloat() * 100 % 2 == 0) {
                        this.randomstr = this.randomstr + this.randomSingle().toString();
                    } else {
                        this.randomstr = this.randomstr + this.randomChar((Character)this.lower.get(0), (Character)this.upper.get(0)).toString();
                    }
                }
            } else {
                for(i = 0; i < this.length; ++i) {
                    this.randomstr = this.randomstr + this.randomSingle().toString();
                }
            }
        } else if (this.upper.size() == 3) {
            for(i = 0; i < this.length; ++i) {
                if ((int)(this.getFloat() * 100.0F) % 2 == 0) {
                    this.randomstr = this.randomstr + this.randomChar((Character)this.lower.get(2), (Character)this.upper.get(2)).toString();
                } else if ((int)(this.getFloat() * 100.0F) % 2 == 0) {
                    this.randomstr = this.randomstr + this.randomChar((Character)this.lower.get(1), (Character)this.upper.get(1)).toString();
                } else {
                    this.randomstr = this.randomstr + this.randomChar((Character)this.lower.get(0), (Character)this.upper.get(0)).toString();
                }
            }
        } else if (this.upper.size() == 2) {
            for(i = 0; i < this.length; ++i) {
                if ((int)(this.getFloat() * 100.0F) % 2 == 0) {
                    this.randomstr = this.randomstr + this.randomChar((Character)this.lower.get(1), (Character)this.upper.get(1)).toString();
                } else {
                    this.randomstr = this.randomstr + this.randomChar((Character)this.lower.get(0), (Character)this.upper.get(0)).toString();
                }
            }
        } else {
            for(i = 0; i < this.length; ++i) {
                this.randomstr = this.randomstr + this.randomChar((Character)this.lower.get(0), (Character)this.upper.get(0)).toString();
            }
        }

    }

    private final Character randomSingle() {
        return new Character(this.single[(int)(this.getFloat() * (float)this.singlecount - 1.0F)]);
    }

    private final Character randomChar(Character lower, Character upper) {
        char low = lower;
        char up = upper;
        int tempval = (int)((float)low + this.getFloat() * (float)(up - low));
        return new Character((char)tempval);
    }

    public final String getRandom() {
        this.randomstr = new String();
        this.generaterandom();
        if (this.hmap != null) {
            while(true) {
                if (!this.hmap.containsKey(this.randomstr)) {
                    this.hmap.put(this.randomstr, (Object)null);
                    break;
                }

                this.generaterandom();
            }
        }

        return this.randomstr;
    }

    public final void setRanges(ArrayList low, ArrayList up) {
        this.lower = low;
        this.upper = up;
    }

    public final void setHmap(HashMap map) {
        this.hmap = map;
    }

    public final void setLength(String value) {
        this.length = new Integer(value);
    }

    public final void setAlgorithm(String value) {
        this.algorithm = value;
        this.secure = true;
    }

    public final void setProvider(String value) {
        this.provider = value;
    }

    public final void setAllchars(boolean value) {
        this.allchars = value;
    }

    public final void setSingle(char[] chars, int value) {
        this.single = chars;
        this.singlecount = value;
        this.singles = true;
    }

    public final void setCharset(String value) {
        boolean more = true;
        this.lower = new ArrayList(3);
        this.upper = new ArrayList(3);
        if (value.compareTo("all") == 0) {
            this.allchars = true;
            more = false;
        } else if (value.charAt(1) == '-' && value.charAt(0) != '\\') {
            while(more && value.charAt(1) == '-' && value.charAt(0) != '\\') {
                this.lower.add(new Character(value.charAt(0)));
                this.upper.add(new Character(value.charAt(2)));
                if (value.length() <= 3) {
                    more = false;
                } else {
                    value = value.substring(3);
                }
            }
        }

        if (more) {
            this.single = new char[30];

            String token;
            for(StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens(); this.single[this.singlecount++] = token.charAt(0)) {
                token = tokens.nextToken();
                if (token.length() > 1) {
                    this.single[this.singlecount++] = '-';
                }
            }
        }

        if (this.lower == null && this.single == null) {
            this.setCharset("a-zA-Z0-9");
        }

    }

    public static String getGUID32(int piNumber) {
        String ls_Guid = getGUID(piNumber);
        ls_Guid = ls_Guid.replaceAll("\\-", "");
        ls_Guid = ls_Guid.replaceAll("\\{", "");
        ls_Guid = ls_Guid.replaceAll("\\}", "");
        return ls_Guid;
    }

    public static String getGUID32() {
        return getGUID32(-1);
    }

    public static String getGUID() {
        return getGUID(-1);
    }

    public static String getGUID(int piNumber) {
        try {
            RandomStrg rstr = new RandomStrg();
            rstr.setCharset("A-F0-9");
            rstr.setLength(12);
            rstr.generateRandomObject();
            String dsNumber = rstr.getRandom();
            if (piNumber < 0) {
                dsNumber = (String.valueOf(getNextId()) + "0000").substring(0, 4) + "-" + dsNumber;
            } else {
                dsNumber = (String.valueOf(piNumber) + "0000").substring(0, 4) + "-" + dsNumber;
            }

            Date d = new Date();
            String ls_DateFormat = "yyyyMMdd-HHmm-ssSSS";
            DateFormat df = new SimpleDateFormat(ls_DateFormat);
            String dsDateTime = df.format(d).substring(0, 18);
            return "{" + dsDateTime + "-" + dsNumber + "}";
        } catch (Exception var7) {
            var7.printStackTrace();
            return "";
        }
    }

    private static synchronized long getNextId() {
        ++id;
        return id;
    }

    public static void main(String[] args) {
        for(int i = 0; i < 100; ++i) {
            new RandomStrg();
            String guid = getGUID32();
            System.out.println(guid.length() + "\n" + guid);
        }

    }
}
